/**
 * @description 遍历树型结构
 * @param data 数据
 * @param callback 回调函数
 * @param childrenName 子节点名称
 */
export function forEachTree(
  data: any,
  callback: Function,
  childrenName = 'children'
) {
  for (let i = 0; i < data.length; i++) {
    callback(data[i])
    if (data[i][childrenName] && data[i][childrenName].length > 0) {
      forEachTree(data[i][childrenName], callback, childrenName)
    }
  }
}

/**
 * 获取对象key
 * @param obj 目标对象
 * @param key 对象key值
 * @returns string
 */
export const getPropKey = <T extends object, K extends keyof T>(
  obj: T,
  key: K
) => {
  return key as string
}

export const getTypeKey = <T>(key: keyof T) => {
  return key as string
}

/**
 * 获取对象value
 * @param obj 目标对象
 * @param key 对象key值
 * @returns obj[key]
 */
export const getPropValue = <T extends object, K extends keyof T>(
  obj: T,
  key: K
) => {
  return obj[key]
}
